package com.example.qxfw.tourqx.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.qx.TownshipStation;
import com.example.qxfw.common.entity.qx.Weather;
import com.example.qxfw.common.entity.zy.BaseProduct;
import com.example.qxfw.common.entity.zy.TourFcst;
import com.example.qxfw.common.entity.zy.TourStations;
import com.example.qxfw.tourqx.service.JdybService;
import com.example.qxfw.rcyw.pojo.JobMake;
import com.example.qxfw.rcyw.service.JobMakeService;
import com.example.qxfw.ybzz.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@ApiIgnore
@Api(tags = "旅游气象-景点预报和景点预报查询接口")
@RestController
@CrossOrigin
@RequestMapping("/jdyb")
public class JdybController {

    @Autowired
    private TourStationsService tourStationsService;

    @Autowired
    private TourFcstService tourFcstService;

    @Autowired
    private WeatherService weatherService;

    @Autowired
    private TownshipStationService townshipStationService;

    @Autowired
    private BaseProductService baseProductService;

    @Autowired
    private JobMakeService jobMakeService;

    @Autowired
    private JdybService jdybService;

    @ApiOperation("获取旅游景点")
    @GetMapping("/getTourStation")
    public SysResult getTourStation(){
        List<TourStations> list = tourStationsService.getList1();
        return SysResult.success(list);
    }

    @ApiOperation("获取观测要素名称")
    @GetMapping("/getTourStation1")
    public SysResult getTourStation1(String stationId){
        List<TourStations> list = tourStationsService.getList2(stationId);
        return SysResult.success(list);
    }

    @ApiOperation("获取预报最新时间")
    @GetMapping("/getMaxTime")
    public SysResult getMaxTime(){
        TourFcst maxTime = tourFcstService.getMaxTime();
        return SysResult.success(maxTime);
    }

    @ApiOperation("获取旅游站点名称")
    @GetMapping("/getTourStationName")
    public SysResult getTourStationName(){
        List<String> stationName = tourStationsService.getStationName();
        return SysResult.success(stationName);
    }

    @ApiOperation("获取天气代码表")
    @GetMapping("/getWeatherCode")
    public SysResult getWeatherCode(){
        List<Weather> weather = weatherService.getWeather();
        return SysResult.success(weather);
    }

    @ApiOperation("更新旅游预报")
    @PostMapping("/updateTourFcst")
    public SysResult updateTourFcst(TourFcst tourFcst){
        TourFcst result = tourFcstService.update(tourFcst);
        if (result != null) {
            return SysResult.success(result);
        }else {
            return SysResult.fail("更新预报失败！！！");
        }
    }

    @ApiOperation("获取乡镇站点信息")
    @GetMapping("/getTownshipStation")
    public SysResult getTownshipStation(){
        List<TownshipStation> list = townshipStationService.getList3();
        return SysResult.success(list);
    }

    @ApiOperation("获取景点预报")
    @GetMapping("/getTourFcst")
    public SysResult getTourFcst(String dateChar,String timeChar,String nTimes,String nTimes24,String nTimes12,String stationName,String forecastType){
        List<TourFcst> list = tourFcstService.getList(dateChar, timeChar, nTimes, nTimes24, nTimes12, stationName, forecastType);
        return SysResult.success(list);
    }

    @ApiOperation("获取景点预报1")
    @GetMapping("/getTourFcst1")
    public SysResult getTourFcst1(String dataChar1,String dateChar2,String forecastType){
        List<TourFcst> list = tourFcstService.getList1(dataChar1, dateChar2, forecastType);
        return SysResult.success(list);
    }

    @ApiOperation("查询产品信息")
    @GetMapping("/getBaseProduct")
    public SysResult getBaseProduct(String productName,String productType){
        List<BaseProduct> list = baseProductService.getList2(productName, productType);
        return SysResult.success(list);
    }

    @ApiOperation("更新产品信息")
    @GetMapping("/updateBaseProduct")
    public SysResult updateBaseProduc(@RequestBody BaseProduct baseProduct){
        Integer rows = baseProductService.updateProduct(baseProduct);
        return SysResult.success();
    }

    @ApiOperation("保存产品信息")
    @PostMapping("/saveBaseProduct")
    public SysResult saveBaseProduct(@RequestBody BaseProduct baseProduct){
        Integer rows = baseProductService.save(baseProduct);
        return SysResult.success(rows);
    }

    @ApiOperation("更新日常业务")
    @PostMapping("/updateJobMake")
    public  SysResult updateJobMake(@RequestBody JobMake jobMake){
        Integer rows = jobMakeService.update(jobMake);
        return SysResult.success(rows);
    }

    @ApiOperation("删除旅游预报")
    @GetMapping("/deleteTourFcst")
    public SysResult deleteTourFcst(String stationId,String dateChar,String timeChar){
        Integer rows = tourFcstService.delete1(stationId, dateChar, timeChar);
        return SysResult.success(rows);
    }

    @ApiOperation("保存旅游预报")
    @PostMapping("/saveTourFcst")
    public SysResult saveTourFcst(@RequestBody TourFcst tourFcst){
        TourFcst result = tourFcstService.save(tourFcst);
        if (result != null) {
            return SysResult.success(result);
        }else {
            return SysResult.fail("保存预报失败！！！");
        }
    }




    @ApiOperation("景点预报查询--查询")
    @GetMapping("/getAllOfTourFcst")
    public SysResult getAllOfTourFcst(String start, String end, int forecasttype){
        List<TourFcst> list = jdybService.getAllOfTourFcst(start, end, forecasttype);
        return SysResult.success(list);
    }

    @ApiOperation("景点预报查询--修改")
    @PutMapping("/updateByNitmeAndStationName")
    public SysResult updateByNitmeAndStationName(@RequestBody TourFcst tourFcst){
        int result = jdybService.updateByNitmeAndStationName(tourFcst);
        return SysResult.success(result);
    }

    @ApiOperation("景点预报查询--删除")
    @DeleteMapping("/deleteByNitmeAndStationName")
    public SysResult deleteByNitmeAndStationName(String stationname, String timechar, int ntimes, int forecasttype){
        int result = jdybService.deleteByNitmeAndStationName(stationname, timechar, ntimes, forecasttype);
        return SysResult.success(result);
    }


}
